using UnityEngine;
using DG.Tweening;

public class MoveAlongCurveDoTween : MonoBehaviour
{
    public Transform pointA; // 起点
    public Transform pointB; // 终点
    public Transform controlPoint; // 控制点
    public float duration = 3.0f; // 移动时间

    private void Start()
    {
        // 设置贝塞尔曲线的路径点
        Vector3[] path = new Vector3[]
        {
            // pointA.position,
            // controlPoint.position,
            // pointB.position
            handle_point(pointA.position),
            handle_point(controlPoint.position),
            handle_point(pointB.position)
        };

        // 使用 DoTween 沿路径运动
        transform.DOPath(path, duration, PathType.CatmullRom)
            .SetEase(Ease.InOutSine) // 设置缓动效果
            .SetOptions(false); // 禁用自动旋转
            // .SetLookAt(0.01f); // 自动朝向路径方向
    }

    public Vector3 handle_point(Vector3 old_point)
    {
        return new Vector3(old_point.x, old_point.y, 0);
    }
    
    // void OnDrawGizmos()
    // {
    //     if (pointA && pointB && controlPoint)
    //     {
    //         Gizmos.color = Color.green;
    //         Gizmos.DrawLine(pointA.position, controlPoint.position);
    //         Gizmos.DrawLine(controlPoint.position, pointB.position);
    //     }
    // }
}